/**
 * 
 */
package fr.lelouet.ga.stoppers;

import fr.lelouet.ga.Generation;
import fr.lelouet.ga.Stopper;

/**
 * Stopper that stops an algorithm when it reaches a given number of generations
 * creation.<br />
 * It cannot be shared amongst several algorithms.<br />
 * It increases its number of generation done each time it is called
 * {@link #stop(Generation)}
 * @author le louet
 */
public class MaxNGenerationsStopper<T> implements Stopper<T> {

  protected int maxGens;

  protected int genDone = 0;

  public MaxNGenerationsStopper(final int maxgens) {
    this.maxGens = maxgens;
  }

  @Override
  public boolean stop(final Generation<T> generation) {
    genDone++;
    return genDone >= this.maxGens;
  }

  @Override
  public void restart() {
    genDone = 0;
  }

}
